<?php

/**
 * Subclass for representing a row from the 'log' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Log extends BaseLog
{
	public static function logThis($parentId, $projectId, $className, $action, $objName, $objId = -1, $userId = 0) 
	{
	    $log = new Log();
		$log->setParentId($parentId);
		$log->setProjectId($projectId);
		$log->setClassName($className);
		$log->setAction($action);
		$log->setObjName($objName);
		$log->setObjId($objId);
		$log->setUserId($userId);
		//echo $parentId . $projectId . $className . $action . $objName . $objId . $userId;
		//die();
		$log->setMd5(md5($parentId . $projectId . $className . $action . $objName . $objId . $userId));
		$log->save();

		return $log->getId();
	}

	public function getUserName() 
	{
	    $user = UserPeer::retrieveByPk($this->getUserId());
		return $user->getNick() . '(' . $user->getEmail() . ')';
	}

	public function getObj() 
	{
	    return 'obj';
	}

	public function isChanged() 
	{
		$md5 = md5($this->getParentId() . $this->getProjectId() . $this->getClassName() . $this->getAction() . $this->getObjName() . $this->getObjId() . $this->getUserId());
	    if( $md5 == $this->getMd5() ) 
	    {
	        return $this->getMd5();
	    }
		else 
		{
		    return 'nesutampa - ' . $md5;
		}
	}
}
